#pragma once
template <typename T, int M>
struct SqList
{
    T elem[M];
    int length;
};

template <typename T, int M>
void InitList(SqList<T, M> &L)
{
    L.length = 0;
}

template <typename T, int M>
void ListInsert(SqList<T, M> &L, int i, T e)
{
    if (L.length == M)
        throw "L is full";
    if (i < 1 || i > L.length + 1)
        throw "Invalid i";

    for (int j = L.length - 1; j >= i - 1; j--)
        L.elem[j + 1] = L.elem[j];

    L.elem[i - 1] = e;

    L.length++;
}

template <typename T, int M>
void ListDelete(SqList<T, M> &L, int i, T &e)
{
    if (L.length == 0)
        throw "L is empty";
    if (i < 1 || i > L.length)
        throw "Invalid i";

    e = L.elem[i - 1];


    for (int j = i; j < L.length; j++)
        L.elem[j - 1] = L.elem[j];

    L.length--;
}
